package com.liuyang.homework.SQL;

import android.database.Cursor;
import android.database.CursorWrapper;

import com.liuyang.homework.Bean.News;

import java.util.UUID;

/**
 * Created by liuyang on 2017/1/14.
 */

public class NewsCursorWrapper extends CursorWrapper {

    public NewsCursorWrapper(Cursor cursor) {
        super(cursor);
    }

    public News getNews(){

        String uuidString = getString(getColumnIndex(NewsDbSchema.NewsTable.Cols.UUID));
        String title = getString(getColumnIndex(NewsDbSchema.NewsTable.Cols.TITLE));
        String content = getString(getColumnIndex(NewsDbSchema.NewsTable.Cols.CONTENT));
        String keyWords = getString(getColumnIndex(NewsDbSchema.NewsTable.Cols.KEYWORDS));
        String source = getString(getColumnIndex(NewsDbSchema.NewsTable.Cols.SOURCE));
        String url = getString(getColumnIndex(NewsDbSchema.NewsTable.Cols.URL));

        int _id = getInt(getColumnIndex(NewsDbSchema.NewsTable.Cols.ID));

        String createdAt = getString(getColumnIndex(NewsDbSchema.NewsTable.Cols.CREATEDAT));

        int isKey = getInt(getColumnIndex(NewsDbSchema.NewsTable.Cols.ISKEY));

        String image = getString(getColumnIndex(NewsDbSchema.NewsTable.Cols.IMAGE));


        News news = new News(UUID.fromString(uuidString));

        news.set_id(_id);
        news.setTitle(title);
        news.setContent(content);
        news.setKey(isKey!=0);
        news.setKeyWords(keyWords);
        news.setCreatedAt(createdAt);
        news.setImage(image);
        news.setUrl(url);
        news.setSource(source);

        return news;
    }
}
